package reflect;

import java.lang.reflect.Method;
import java.lang.reflect.Modifier;

/*课堂练习

 */
public class Test {
    public static void main(String[] args) throws Exception{
        //使用凡是机制调用person类中所有公开方法且无参的方法
        Class cla = Class.forName("reflect.Person");
        Method[] methods = cla.getMethods();
        Object object = cla.newInstance();
        for (Method method: methods){
            //String name = method.getName();
            int parameterCount = method.getParameterCount();
            int modifiers = method.getModifiers();
            if (modifiers == Modifier.PUBLIC && parameterCount ==0){
                method.invoke(object);
            }
        }
    }
}
